package com.mis.clothespos.echarts.controller;


import com.mis.clothespos.clothestype.domain.clothestype;
import com.mis.clothespos.clothestype.service.IclothestypeService;
import com.mis.clothespos.common.AjaxResult;
import com.mis.clothespos.common.BaseController;
import com.mis.clothespos.echarts.domain.OrderItem;
import com.mis.clothespos.echarts.domain.chartsDate;
import com.mis.clothespos.echarts.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/echarts")
public class EchartsController extends BaseController{

    @Autowired
    IclothestypeService iclothestypeService;
    @Autowired
    OrderService orderService;

    @GetMapping("/getTypeRecordByNowDay")
    @ResponseBody
    public AjaxResult getTypeRecordByNowDay(){
        AjaxResult result = new AjaxResult();
        List<clothestype> typeList=iclothestypeService.selectClothesType();
        ArrayList<chartsDate>  chartsDates=new ArrayList<chartsDate>();
        ArrayList<String> typeNameList=new ArrayList<String>();
        for(int i=0;i<typeList.size();i++){
            Long totalPrice= Long.valueOf(0);
            typeNameList.add(typeList.get(i).getDesciption());
            List<OrderItem> orderItems=orderService.getTypeRecordByNowDay(typeList.get(i).getId());
            chartsDate chartsDates1=new chartsDate();
            chartsDates1.setName(typeList.get(i).getDesciption());
            for(int j=0;j<orderItems.size();j++){
                totalPrice=totalPrice+orderItems.get(j).getPrice();
            }
            System.out.println(String.valueOf(totalPrice));
            chartsDates1.setValue(Double.valueOf(String.valueOf(totalPrice)));
            chartsDates.add(chartsDates1);
        }
        result.put("typeNameList",typeNameList);
        result.put("chartsDates",chartsDates);
        return  result;
    }

    @GetMapping("/getTypeRecordBySevenDay")
    @ResponseBody
    public AjaxResult getTypeRecordBySevenDay(){
        AjaxResult result = new AjaxResult();
        List<clothestype> typeList=iclothestypeService.selectClothesType();
        ArrayList<chartsDate>  chartsDates=new ArrayList<chartsDate>();
        ArrayList<String> typeNameList=new ArrayList<String>();
        for(int i=0;i<typeList.size();i++){
            Long totalPrice= Long.valueOf(0);
            typeNameList.add(typeList.get(i).getDesciption());
            List<OrderItem> orderItems=orderService.getTypeRecordBySevenDay(typeList.get(i).getId());
            chartsDate chartsDates1=new chartsDate();
            chartsDates1.setName(typeList.get(i).getDesciption());
            for(int j=0;j<orderItems.size();j++){
                totalPrice=totalPrice+orderItems.get(j).getPrice();
            }
            System.out.println(String.valueOf(totalPrice));
            chartsDates1.setValue(Double.valueOf(String.valueOf(totalPrice)));
            chartsDates.add(chartsDates1);
        }
        result.put("typeNameList",typeNameList);
        result.put("chartsDates",chartsDates);
        return  result;
    }

    @GetMapping("/getStyleRecordByNowDay")
    @ResponseBody
    public AjaxResult getStyleRecordByNowDay(){
        AjaxResult result=new AjaxResult();
        List<OrderItem> orderItems=orderService.getStyleRecordByNowDay();
        ArrayList<String>  stylenameList=new ArrayList<String>();
        ArrayList<Long>    totalPriceList=new ArrayList<Long>();
        for(int i=0;i<orderItems.size();i++){
            String xname=orderItems.get(i).getStyelname()+"("+orderItems.get(i).getDesciption()+")";
            stylenameList.add(xname);
            totalPriceList.add(orderItems.get(i).getTotalprice());
        }
        result.put("stylenameList",stylenameList);
        result.put("totalPriceList",totalPriceList);
        return  result;
    }

    @GetMapping("/getStyleRecordBySevenDay")
    @ResponseBody
    public AjaxResult getStyleRecordBySevenDay(){
        AjaxResult result=new AjaxResult();
        List<OrderItem> orderItems=orderService.getStyleRecordBySevenDay();
        ArrayList<String>  stylenameList=new ArrayList<String>();
        ArrayList<Long>    totalPriceList=new ArrayList<Long>();
        for(int i=0;i<orderItems.size();i++){
            String xname=orderItems.get(i).getStyelname()+"("+orderItems.get(i).getDesciption()+")";
            stylenameList.add(xname);
            totalPriceList.add(orderItems.get(i).getTotalprice());
        }
        result.put("stylenameList",stylenameList);
        result.put("totalPriceList",totalPriceList);
        return  result;
    }


}
